package com.leyou.item.controller;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.entitry.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 张伟奇
 * @Date 2021/7/14 3:48
 * @description
 * @Version 1.0
 **/
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 根据父类目id,查询子类目的集合
     * @param pid
     * @return
     */

    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>>  listCategoryByPid(@RequestParam("pid") Long pid){

        List<CategoryDTO> categoryDTOS = categoryService.listCategoryByPid(pid);

        return ResponseEntity.ok(categoryDTOS);
    }

    /**
     * 根据分类id，查询商品分类
     * @param id
     * @return
     */

    @GetMapping("/{id}")
    public ResponseEntity<List<CategoryDTO>> listCategorySoftById(@PathVariable("id") Integer id){

        List<CategoryDTO> categoryDTOS = categoryService.listCategorySoftById(id);

        return ResponseEntity.ok(categoryDTOS);
    }

    /**
     * 根据分类的集合，查询商品的分类集合
     * @param ids
     * @return
     */

    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> listCategorySoftByIds(@RequestParam("ids") List<Integer> ids){
        List<CategoryDTO> categoryDTOS = categoryService.listCategorySoftByIds(ids);
        return ResponseEntity.ok(categoryDTOS);
    }

    /**
     * 根据品牌id，查询商品分类的集合
     * @param id
     * @return
     */
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> listCategoryByBrandId(@RequestParam("id") Integer id){
        List<CategoryDTO> categoryByBrandId = categoryService.findCategoryByBrandId(id);
        return ResponseEntity.ok(categoryByBrandId);
    }
}
